package mysql

import (
	"beergo/lib/tool"
	"fmt"
)

func CreateController(c *Creator) {
	data := twigger.Render("/mysql/controller.twig", c)
	createControllerFile(c, []byte(data))
}

func createControllerFile(c *Creator, content []byte) {
	path := fmt.Sprintf(
		"%s/app/%s/auto/controller/%sController.go",
		root, c.Table.Path, c.Table.Name)
	tool.CreateFile(path, content)
}

func CreateEmptyController(c *Creator) {
	data := twigger.Render("/mysql/controller_admin.twig", c)
	createEmptyControllerFile(c, []byte(data))
}

func createEmptyControllerFile(c *Creator, content []byte) {
	path := fmt.Sprintf(
		"%s/app/%s/controller/admin/%sAdminController.go",
		root, c.Table.Path, c.Table.Name)
	if !tool.FileExist(path) {
		tool.CreateFile(path, content)
	}
}
